package com.cg.cn.p1_Demo;

import java.util.Random;
import java.util.Scanner;

/*
    2.我们键盘录入一个[1,100]之间的数字,让程序使用Random产生数字猜测,看看程序多少次可以猜对?
 */
public class Demo05BootGuessNumber {
    public static void main(String[] args) {
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        int inputNum = sc.nextInt();
        int count = 0;
        while (true) {
            int guessNum = r.nextInt(100) + 1;
            System.out.println("请输入您猜测的数字(1到100之间的): ");
            if (inputNum > guessNum) {
                count++;
                System.out.println("猜的数据大了");
            } else if (inputNum < guessNum) {
                count++;
                System.out.println("猜的数据小了");
            } else {
                System.out.println("喜你猜中了");
                count++;
                break;
            }
        }
        System.out.println("程序一共猜了"+count+"次");
    }
}
